package models

import (
	"github.com/astaxie/beego/orm"
)

type Molecule struct {
	Id                 int64
	MolId              string `orm:"size(10);index"`
	MolName            string `orm:"size(256);index"`
	Cas                string `orm:"size(20);index"`
	Chembl             string `orm:"size(20);index"` //ChEMBL id
	Pubchem            string `orm:"size(20);index"` //PubChem id
	Drugbank           string `orm:"size(20);index"` //DrugBank id
	Zinc               string `orm:"size(20);index"` //zinc id
	Unii               string `orm:"size(20);index"` // ???
	MolFormula         string `orm:"size(20)"`
	MolImg             string `orm:"size(20)"`
	MolFile            string `orm:"size(20)"`
	Iupac              string `orm:"type(text);null"`
	Smile              string `orm:"type(text);null"`
	InchiKey           string `orm:"size(50);index"`
	Synonyms           string `orm:"type(text);null"`
	MolWeight          float64
	Hac                int64   // Heavy Atom Count
	Hba                int64   // Hydrogen Bond Accpetor
	Hbd                int64   // Hydrogen Bond Donor
	Rbc                int64   // Rotatable Bond Count
	Psa                float64 // Polar Surface Area
	ALogp              float64
	RelationId         string `orm:"size(256)"`
	IndicationId       string `orm:"type(text);null"`
	BindDb             string `orm:"size(20);index"`
	Pdbe               string `orm:"size(20);index"`
	RingsCount         int64
	ComplexPdbsZipFile string `orm:"size(32)"`
}

func (m *Molecule) TableName() string {
	return "molecule"
}

func (m *Molecule) Insert() error {
	if _, err := orm.NewOrm().Insert(m); err != nil {
		return err
	}
	return nil
}

func (m *Molecule) Read(fields ...string) error {
	if err := orm.NewOrm().Read(m, fields...); err != nil {
		return err
	}
	return nil
}

func (m *Molecule) Update(fields ...string) error {
	if _, err := orm.NewOrm().Update(m, fields...); err != nil {
		return err
	}
	return nil
}

func (m *Molecule) Delete() error {
	if _, err := orm.NewOrm().Delete(m); err != nil {
		return err
	}
	return nil
}

func (m *Molecule) Query() orm.QuerySeter {
	return orm.NewOrm().QueryTable(m)
}
